import { Component, OnInit, ViewChild } from '@angular/core';
import { ColumnType, SPage, TablePageComponent } from '@shared/components/table-page/table-page.component';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import { ApiService } from '@core/services/api';
import { _HttpClient } from '@delon/theme';
import { ServerEditComponent } from '../server-edit/server-edit.component';

@Component({
  selector: 'app-server-list',
  templateUrl: './server-list.component.html',
  styles: []
})
export class ServerListComponent implements OnInit {
  @ViewChild("st",{static:false}) st:TablePageComponent;
  selectedData:any[];
  config: SPage = {
    columns: [
      {
        index: 'type',
        title: '类型',
      },
      {
        index: 'serverName',
        title: '名称',
        filter:{
          placeholder: '请输入名称',
          type: 'string'
        }
      },
      {
        index: 'serverValue',
        title: '值',
      },
      {
        index: 'remark',
        title: '备注'
      }
    ],
    showCheckBox: true,
    reqUrl: "",
    editBtn: [
      { title: '编辑'},
      {title:'删除'}
    ]
  }



  constructor(private api : ApiService, private msg : NzMessageService, private modal : NzModalService,private http : _HttpClient) { }

  ngOnInit() {
  }

  operate(e: any): void {
    if (e.title === '编辑') {
      this.editDic(1, e.data);
    }else if(e.title == '删除'){
      
    }
  }

    // 编辑功能开始
    editDic(type: 0 | 1 = 0, _param?: object): void {
      this.modal.create({
        nzTitle: type === 0 ? '新增'  : '编辑',
        nzContent: ServerEditComponent,
        nzWidth: 800,
        nzComponentParams: {
          type,
          _param
        },
        nzOnOk:()=>{
          this.st.reload();
        },
        nzFooter: null
      })
    }

    delData(id:string){
      this.modal.confirm({
        nzTitle: '确定删除?',
        nzOnOk: () => {
          const body = [];
          this.http.put(this.api.role.delete.url,body).subscribe(res => {
            if (res.status === '200') {
              this.msg.success('删除成功');
              this.st.reload();
            }else{
              this.msg.error(res.message);
            }
          })
        }
      })
    }

    _console(e: any): void {
      this.selectedData = e;
    }



}
